<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-1.11.3.min.js"></script>
</head>
<body>
<h1>
    登陆成功</h1>
<button onclick="checkAdmin()">检测ROLE_ADMIN角色</button>
<button onclick="checkUser()">检测ROLE_USER角色</button>
<button onclick="window.location.href='/loginHtml'">退出登录</button>

<script type="application/javascript">
    function checkAdmin() {
        $.ajax({
            url: "/data/admin",
            type: "POST",
            success: function(r, textStatus, request) {
                alert(r)
            }
        })
    }

    function checkUser() {
        $.ajax({
            url: "/data/user",
            type: "POST",
            success: function(r, textStatus, request) {
                debugger
                alert(r)
            }
        })
    }

    $(function() {
        //全局的ajax访问，处理ajax清求时异常
        $.ajaxSetup({
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            global: true,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", localStorage.getItem('token'));
            },
            success: function(result,status,xhr) {
            },
            complete:function(XMLHttpRequest,textStatus){
            }
        });
    })
</script>
</body>
</html>